package com.huluobo.a2107kotlinshopping

import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.huluobo.a2107kotlinshopping.base.BaseMVVMActivity
import com.huluobo.a2107kotlinshopping.databinding.ActivityMainBinding

/**
 * 使用Navigation搭建主界面,总结:
 * 1.在res下生成Navigation文件夹,穿件Navigation图标表
 * 2.添加几个fragment在图表中
 * 3.创建menu,有几个fragment就写几个item,**********注意********** item的id必须和图表中fragment的id一致,否则会找不到对应的fragment,无法切换
 * 4.在main的xml中拉出一个控件NavHostFragment,直接拉会报错,需要修改为fragment
 * 5.给生成NavHostFragment添加刚刚生成图表,也就是main_nav
 * 6.设置底部导航栏和导航控制器(图表)联动
 */
class MainActivity : BaseMVVMActivity<ActivityMainBinding>() {
    override fun initData() {
    }

    override fun initView() {
        //获取导航控制器
        val navHostFragment = supportFragmentManager.findFragmentById(R.id.main_nav_host_fragment) as NavHostFragment
        val navController = navHostFragment.navController

        //绑定底部导航栏和导航控制器
        dataBinding.mainBottomNav.setupWithNavController(navController)
    }

    override fun getLayoutId(): Int = R.layout.activity_main
}